using System.Data;
using System.Data.SqlClient;
using CoreLibrary.Sql;

namespace Entities.DataBase.Sql {

    public class UpdateOutputIntGuid : ISqlScalar<int> {
        
        private readonly int    _value;
        private readonly string _tableName;

        public UpdateOutputIntGuid(string tableName, int value) {
            _tableName = tableName;
            _value     = value;
        }

        public string GetSQL() {
            return string.Format(@"
                   UPDATE {0}
                   SET GUID = GUID + @value 
                   OUTPUT inserted.GUID
                   WHERE ID = 'INT_GUID_ID';
            ",
            _tableName);
        }

        public void SetParameters(SqlCommand command) {
            command.CommandType = CommandType.Text;
            command.Parameters.Add("@value", SqlDbType.Int).Value = _value;
        }

        public int GetResult(SqlConnection conn, object result) {
            return (int)result;
        }
    }
}